import { defineStore } from 'pinia'

export const useHistoryStore = defineStore('history', {
  state: () => ({
    historyList: ['炒锅2', '炒锅3', '炒锅4', '炒锅5'] as string[]
  }),
  getters: {
    getHistoryList: (state) => state.historyList
  },
  actions: {
    addHistory(keyword: string) {
      this.historyList.unshift(keyword)
    },
    clearHistory() {
      this.historyList = []
    },
    removeHistory(keyword: string) {
      this.historyList.splice(this.indexOfHistory(keyword), 1)
    },
    setHistoryList(list: string[]) {
      this.historyList = list
    },
    indexOfHistory(keyword: string) {
      return this.historyList.indexOf(keyword)
    }
  },
  persist: true

})
